﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_AmeTypeManage : System.Web.UI.Page
{
    public string orderOftype;
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlDataSource1.SelectCommand = "select AmerceTypeID as 编号,AmerceName as 类型名, AmerceMoney as 最大借阅数量 from Amerce_info order by  cast   (AmerceTypeID   as   int) ";
        /// SqlDataSource1.SelectParameters["name"].DefaultValue = Session["userName"].ToString();
        /// 


    }
    protected void delete_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in mybookdata.Rows)
        {
            Control ctrl = row.FindControl("CheckBox");

            if ((ctrl as CheckBox).Checked)
            {
                TableCellCollection cell = row.Cells;
                string typeid = cell[1].Text;
                SQL sql = new SQL();
                sql.EXQSQL("delete from Amerce_info where AmerceTypeID='" + typeid + "'");
            }
        }
        Response.Write("<script language=javascript>alert('删除成功');window.location = 'AmeTypeManage.aspx';</script>");
    }

    protected void change_Click(object sender, EventArgs e)
    {
        //try
        //{

        //    int i = Convert.ToInt32(TextBox1.Text);
        //    SQL sql = new SQL();
        //    sql.EXQSQL("update book_type set Amerce_info='" + TextBox1.Text + "' ,AmerceMoney='" + TextBox2.Text + "' where  booktype='" + TextBox1.Text + "'");
        //    Response.Write("<script language=javascript>alert('修改成功');window.location = 'AmeTypeManage.aspx';</script>");
        //}
        //catch (System.Exception ex)
        //{
        //    Label1.Text = "警告：您输入有误";
        //}

        foreach (GridViewRow row in mybookdata.Rows)
        {
            Control ctrl = row.FindControl("CheckBox");

            if ((ctrl as CheckBox).Checked)
            {
                TableCellCollection cell = row.Cells;
                string typeid = cell[1].Text;
                SQL sql = new SQL();


                try
                {

                    sql.EXQSQL("update Amerce_info set AmerceName='" + TextBox1.Text + "' ,AmerceMoney=" + TextBox2.Text + " where  AmerceTypeID='" + typeid + "'");
                    Response.Write("<script language=javascript>alert('修改成功');window.location = 'AmeTypeManage.aspx';</script>");


                }
                catch (System.Exception ex)
                {
                    Response.Write("<script language=javascript>alert('你的输入有误啦');window.location = 'AmeTypeManage.aspx';</script>");
                    Label1.Text = "警告：您输入有误";
                }

            }
        }

    }

    protected void chaxun_Click(object sender, EventArgs e)
    {

    }
    protected void sureAdd_Click(object sender, EventArgs e)
    {
        try
        {
            string i = TypeID.Text;
            SQL sql = new SQL();
            string id = sql.EXQSQL("select top 1  * from Amerce_info order by AmerceTypeID desc");
            int bid = Convert.ToInt32(id);
            bid++;
            sql.EXQSQL("insert into Amerce_info values(" + bid + ",'" + i + "','" + Typename.Text + "') ");
            Response.Write("<script language=javascript>alert('增加成功');window.location = 'AmeTypeManage.aspx';</script>");
        }
        catch (System.Exception ex)
        {
            Response.Write("<script language=javascript>alert('ERROR！');window.location = 'AmeTypeManage.aspx';</script>");
            Label1.Text = "警告：您输入的类别有误";
        }



    }



    protected void CheckBox_CheckedChanged(object sender, EventArgs e)
    {
        int Pretid = 0;
        foreach (GridViewRow row in mybookdata.Rows)
        {
            Control ctrl = row.FindControl("CheckBox");

            if ((ctrl as CheckBox).Checked)
            {
                TableCellCollection cell = row.Cells;
                string typeid = cell[1].Text;
                SQL sql = new SQL();
                string id = sql.EXQSQL("select AmerceName from Amerce_info where AmerceTypeID='" + typeid + "'");
                string AmerceMoneystr = sql.EXQSQL("select AmerceMoney from Amerce_info where AmerceTypeID='" + typeid + "'");

                try
                {
                   
                    TypeID.Text = id;

                    TextBox2.Text = AmerceMoneystr;
                    TextBox1.Text = id;



                }
                catch (System.Exception ex)
                {
                   
                    TypeID.Text = id;

                    TextBox2.Text = AmerceMoneystr;
                    TextBox1.Text = id;


                }

            }
        }
    }
}